Geolocation based Speedometer and Compass


Posted by wayne201299 on 2023-10-03

DEMO

取得目前移動速度,以及指北針

實作

  1. 同上篇,要取得瀏覽器定位功能所以要先啟動本地server
  2. 監聽Web API 的地理位置變化事件

     const arrow = document.querySelector(".arrow");
     const speed = document.querySelector(".speed-value");
    
     navigator.geolocation.watchPosition(
         (position) => {
             speed.textContent = position.coords.speed;
             arrow.style.transform = `rotate(${position.coords.heading}deg)`;
         },
         (err) => {
             console.log(err);
             alert("Geolocation is not supported by this browser.");
         }
     );
    

總結

  • 了解如何透過navigator.geolocation取得目前地理位址

#javascript







Related Posts

滲透測試基本技術 第三章 (005)

滲透測試基本技術 第三章 (005)

[ week 2 ]  打造 JaveScript 的基礎 - 基本運算 &位元運算

[ week 2 ] 打造 JaveScript 的基礎 - 基本運算 &位元運算

pWnOS v2.0 Walkthrough

pWnOS v2.0 Walkthrough


Comments